/*
* @Author: xfy
* @Date:   2017-09-07 12:39:27
* @Last Modified by:   xfy
* @Last Modified time: 2017-09-15 14:45:13
*/
'use strict';
var _supper = require('util/supper.js');
var _adminProduct = {
    //注册声纹
    registerVoice : function(listParam, resolve, reject){
        _adminProduct.request({
            url     : _supper.getServerUrl('/voice/registerVoice.do'),
            data    : listParam,
            method  : 'POST',
            success : resolve,
            error   : reject
        });
    },
    //删除声纹
    deleteVoice : function(listParam, resolve, reject){
        _supper.request({
            url     : _supper.getServerUrl('/voice/removeVoice.do'),
            data    : {
                idNo : listParam.idNo
            },
            method  : 'POST',
            success : resolve,
            error   : reject
        });
    },
    selectVoice : function(listParam, resolve, reject){
        _supper.request({
            url     : _supper.getServerUrl('/voice/selectVoice.do'),
            data    : {
                idNo : listParam.idNo
            },
            method  : 'POST',
            success : resolve,
            error   : reject
        });
    },
    //网络请求
    request : function(param){
        var _this = this;
        $.ajax({
            type        : param.method          || 'get',
            url         : param.url             || '',
            async       : !param.async,
            dataType    : param.type            || 'json',
            processData: false,
        	cache: false,
        	contentType: false,
            data        : param.data            || '',
            success     : function(res){
                //请求成功
                if(1 === res.status){
                    typeof param.success === 'function' && param.success(res.data, res.msg);
                }
                //未登录状态
                else if(10 === res.status){
                    _this.doLogin();
                }
                //非管理员用户
                else if(20 === res.status){
                    _this.doAdminLogin();
                }
                //请求参数错误
                else if(0 === res.status){
                    typeof param.error === 'function' && param.error(res.msg);
                }
            },
            error       : function(err){
                typeof param.error === 'function' && param.error(err.statusText);
            }
        });
    }
}
module.exports = _adminProduct;